package cn.darkhorse.messystem.service.impl;

import cn.darkhorse.messystem.dao.MesSysPermsDao;
import cn.darkhorse.messystem.service.IMesSysPermsService;
import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;

@Service
public class IMesSysPermsServiceImpl implements IMesSysPermsService {
    @Resource
    private MesSysPermsDao mesSysPermsDao;
    /**
     * 获取有权限的所有用户
     *
     * @param perms
     * @return
     */
    @Override
    public List<SysUser> getUsersByPerms(String perms) {
        List<SysUser> usersByPerms = mesSysPermsDao.getUsersByPerms(perms);
        //去重
        List<SysUser> newList = usersByPerms.stream().collect(Collectors
                .collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SysUser::getUserId))),
                        ArrayList::new));
        return newList;
    }
}
